/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * @author yaoyuming
 * @date  2019-12-04 17:41
 */
package com.yao.cloud.consumer.config;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Console;
import feign.Response;
import feign.codec.Decoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author yaoyuming
 * @date 2019/12/04 17:41
 */
@Configuration
public class FeignConfiguration {

    @Bean
    public Decoder feignDecoder() {
        return (response, type) -> {
            Response.Body body = response.body();
            Console.log("body = {}", body);

            String read = IoUtil.read(body.asInputStream(), "UTF-8");
            List<String> collect = Stream.of(read.split(",")).collect(Collectors.toList());

            Console.log("strings = {}", collect);
            return collect;
        };
    }


}